package cn.fabrice.common;

import lombok.Data;

import java.io.Serializable;
@Data
public class BaseResponse<T> implements Serializable {

    private Integer code; //编码：1成功，0和其它数字为失败
    private T data; //数据
    private String msg; //错误信息
    private String description; //详细错误信息

    public static <T> BaseResponse<T> success() {
        BaseResponse<T> baseResponse = new BaseResponse<T>();
        baseResponse.code = 1;
        baseResponse.msg = "ok";
        baseResponse.description = "ok";
        return baseResponse;
    }

    public static <T> BaseResponse<T> success(T object) {
        BaseResponse<T> baseResponse = new BaseResponse<T>();
        baseResponse.data = object;
        baseResponse.code = 1;
        baseResponse.msg = "ok";
        baseResponse.description = "ok";
        return baseResponse;
    }

    public static <T> BaseResponse<T> error(Integer code ,String msg,String description) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.description=description;
        baseResponse.msg = msg;
        baseResponse.code = code;
        return baseResponse;
    }
    public static <T> BaseResponse<T> error(ErrorCode errorCode) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.description=errorCode.getDescription();
        baseResponse.msg = errorCode.getMessage();
        baseResponse.code = errorCode.getCode();
        return baseResponse;
    }
}
